﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Authorization
{
    public static class ThreadPoolTimeoutWorkaround
    {
        static ManualResetEvent s_dummyEvent;
        static RegisteredWaitHandle s_registeredWait;

        public static void DoWorkaround()
        {
            // Create an event that is never set
            s_dummyEvent = new ManualResetEvent(false);

            // Register a wait for the event, with a periodic timeout. This causes callbacks
            // to be queued to an IOCP thread, keeping it alive
            s_registeredWait = ThreadPool.RegisterWaitForSingleObject(
                s_dummyEvent,
                (a, b) =>
                {
                    // Do nothing
                },
                null,
                1000,
                false);
        }
    }
}
